﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YouYi.YingShengBack.Web.Models;

namespace YouYi.YingShengBack.Web.Attributes
{
    public class ActionAttribute : ActionFilterAttribute  //行为过滤器
    {

        /// <summary>
        /// 调用控制器对应的Action方法之后的操作
        /// </summary>
        /// <param name="filterContext"></param>
        //public override void OnActionExecuted(ActionExecutedContext filterContext)
        //{
        //    if (AdminContext.adminContext.adminInfo != null)
        //    {
        //        //获取用户名
        //        string username = AdminContext.adminContext.adminInfo.Name;
        //        string controller = filterContext.RouteData.Values["Controller"].ToString();
        //        string action = filterContext.RouteData.Values["Action"].ToString();
        //        //获取系统的日志
        //        string msg = $"时间:{DateTime.Now},用户名:{username},已完成控制器:{controller},页面:{action}";
        //        //获取文件路径
        //        string path = "D:\\lj.txt";
        //        File.AppendAllText(path, msg);
        //    }
        //}


        ///// <summary>
        ///// 调用控制器对应的Action方法之前的操作
        ///// </summary>
        ///// <param name="filterContext"></param>
        //public override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    if (AdminContext.adminContext.adminInfo != null)
        //    {
        //        //获取用户名
        //        string username = AdminContext.adminContext.adminInfo.Name;
        //        string controller = filterContext.RouteData.Values["Controller"].ToString();
        //        string action = filterContext.RouteData.Values["Action"].ToString();
        //        //获取系统的日志
        //        string msg = $"时间:{DateTime.Now},用户名:{username},正在操作控制器:{controller},页面:{action}";
        //        //获取文件路径
        //        string path = "D:\\Exception.txt";
        //        File.AppendAllText(path, msg);
        //    }
        //}

        /// <summary>
        /// 调用控制器对应的Action方法之后页面渲染之后的操作
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {

        }

        /// <summary>
        /// 调用控制器对应的Action方法之后页面渲染之前的操作
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {

        }
    }
}